package com.jiantong.work.impl.manager;

import com.jiantong.user.model.UserProfile;
import com.jiantong.work.impl.dao.yangzhibaoxian.InsuranceApplicationDao;
import com.jiantong.work.impl.dao.yangzhibaoxian.InsuranceRetailDao;
import com.jiantong.work.model.yangzhibaoxian.InsuranceApplication;
import com.jiantong.work.model.yangzhibaoxian.InsuranceArea;
import com.jiantong.work.model.yangzhibaoxian.InsuranceRetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by ThinkPad on 2017/9/8.
 */
@Component
public class InsuranceApplicationManager {
    private InsuranceApplicationDao insuranceApplicationDao;
    private InsuranceRetailDao insuranceRetailDao;
    @Autowired
    public InsuranceApplicationManager(InsuranceApplicationDao insuranceApplicationDao,InsuranceRetailDao insuranceRetailDao) {
        this.insuranceApplicationDao = insuranceApplicationDao;
        this.insuranceRetailDao=insuranceRetailDao;
    }
    @Transactional
    public Long create(InsuranceApplication insuranceApplication, List<InsuranceRetail> insuranceRetailList) {

        insuranceApplicationDao.create(insuranceApplication);
        System.out.print(insuranceApplication.getId());

        for (InsuranceRetail insuranceRetail:insuranceRetailList){
            insuranceRetail.setApplication_id(insuranceApplication.getId());
        }
        insuranceRetailDao.creates(insuranceRetailList);
        return insuranceApplication.getId();

    }
}
